/**
 * 敌机类
 * */
function Enemy(x,y,shootX,shootY,bitmapData,hp){
    base(this,Plain,[x,y,shootX,shootY,bitmapData,hp]);
    var self = this;
    self.belong = "enemy";
}

/**
 * 循环
 * */
Enemy.prototype.onframe = function (){
    var self = this;
    self.callParent("onframe",arguments);
    var isOut = false;

    if(self.x < -self.getWidth() || self.x > LGlobal.width ||
        self.y < -self.getHeight() || self.y > LGlobal.height){
        isOut = true;
    }

    if(isOut){
        self.whenOut();
    }

    if(self.isdie || self.hp <= 0){
        self.removeRun();
    }
    var self=this;
    var key,plain;
    if(self.belong == player.belong){
        for(key in plainLayer.childList){
            plain = plainLayer.childList[key];
            if(player.objectindex != plain.objectindex && LGlobal.hitTestArc(self,plain)){
                plain.hp--;
                self.isdie=true;
                self.bitmap.bitmapData = new LBitmapData(datalist["remove"]);
                self.bitmap.x = -self.bitmap.getWidth() * 0.4;
                self.bitmap.y = -self.bitmap.getHeight() * 0.4;
                if(player){
                    plainLayer.removeChild(player);
                }
            }
        }
    }else{
        if(LGlobal.hitTestArc(self,player)){
            player.hp--;
            self.isdie=true;
            self.bitmap.bitmapData = new LBitmapData(datalist["remove"]);
            if(player){
                plainLayer.removeChild(player);

            }
        }
    }
};

Enemy.prototype.whenOut = function (){
    var self = this;
    if(self.move.length > 0){
        self.move.splice(0,2);
    }
    if(self.move.length == 0){
        self.isdie = true;
    }
};

Enemy.prototype.removeRun = function (){
    var self = this;
    if(self.alpha <= 0){
        zhiSound.stop();
        boomSound.setVolume(0.8);
        boomSound.play();
        self.sendInfo();
        plainLayer.removeChild(self);
        return false;
    }
    self.bitmap.scaleX+=0.2;
    self.bitmap.scaleY+=0.2;
    self.bitmap.x = -self.bitmap.getWidth() * 0.2;
    self.bitmap.y = -self.bitmap.getHeight() * 0.2;
    self.alpha-=0.1;
}
Enemy.prototype.sendInfo=function(){
    isKit=1;
    hitNum++;
    createMask();
    showLoading(maskLayer);
    if(LGlobal.platforms=="sohuNews"){
        if(hitNum==1){
            gameFail("go")
        }else{
            $SohuNewsScope.luckyDrawDraw.draw(11, p1, function (data) {
                if(!localStorage.getItem("lotteyLink")){
                    if (data.copyWritingType == 2) {
                        gameSuccess(data.copy_Writing_Link);
                        localStorage.setItem("lotteyLink",data.copy_Writing_Link);
                    } else if(data.copyWritingType == 1){
                        if(hitNum==eggs_num){
                            gameFail("stop");
                        }else{
                            gameFail("go");
                        }
                    }
                }else{
                    var link=localStorage.getItem("lotteyLink");
                    if(link==data.copy_Writing_Link){
                        if(hitNum==eggs_num){
                            gameFail("stop");
                        }else{
                            gameFail("go");
                        }
                    }else{
                        if (data.copyWritingType == 2) {
                            gameSuccess(data.copy_Writing_Link);
                            localStorage.setItem("lotteyLink",data.copy_Writing_Link);
                        } else if(data.copyWritingType == 1){
                            if(hitNum==eggs_num){
                                gameFail("stop");
                            }else{
                                gameFail("go");
                            }
                        }
                    }
                }
            }, function () {
                canShot = true;
                console.log("fail");
                hideLoading(maskLayer);
                clearInterval(showLoadingGo);
                if(hitNum==eggs_num){
                    gameFail("stop");
                }else{
                    gameFail("go");
                }
            });
        }
    }else{
        if(hitNum==1){
           gameFail("go");
        }else{
            if(hitNum==eggs_num){
                gameFail("stop");
            }else{
                gameFail("go");
            }
        }
    }
}